<template>
	<view class="pb-30" v-if="data&&data.id">
		<image class="fixed top-0 index--1" style="width: 750rpx; height: 634rpx" src="/static/page-bg.png"></image>
		<uv-navbar :fixed="false" bgColor="transparent">
			<view slot="left">
				<nav-left></nav-left>
			</view>
		</uv-navbar>

		<!-- 状态和按钮 -->
		<view class="status-and-button mt-20 flex">
			<view class="flex-1 color-primary">
				<view class="fs-34 fw-700">{{getSname(data)}}</view>
				<view class="fs-24" style="margin-top: 18rpx" v-if="data.status != '40'">{{data.batchNumber}}
					{{getSname(data)}}！
				</view>
				<block v-else>
					<view class="fs-24" style="margin-top: 18rpx" v-if="data.stepStatus1 == 1 && data.stepStatus2 == 0">
						订单工序1.型材切割 已完成！</view>
					<view class="fs-24" style="margin-top: 18rpx" v-if="data.stepStatus2 == 1 && data.stepStatus3 == 0">
						订单工序2.百叶制作 已完成！</view>
					<view class="fs-24" style="margin-top: 18rpx" v-if="data.stepStatus3 == 1 && data.stepStatus4 == 0">
						订单工序3.玻璃制作 已完成！</view>
					<view class="fs-24" style="margin-top: 18rpx" v-if="data.stepStatus4 == 1 && data.stepStatus5 == 0">
						订单工序4.成品组装 已完成！</view>
					<view class="fs-24" style="margin-top: 18rpx" v-if="data.stepStatus5 == 1">订单工序5.包装检验 已完成！</view>
				</block>
			</view>
		</view>
		<!-- 客户信息 -->
		<view class="shipping-info module-wrap bg-f radius-10 mx-20">
			<view class="module-name fw-700  flex">批次信息
				<view style="display: flex;align-items: center;" class="customer-name fs-30 fw-700">
					<view class="tts" v-if="data.priority == '1'">
						加急
					</view>
				</view>
			</view>
			<view class="shipping-item flex">
				<view class="label">批次号：</view>
				<view class="flex-1">{{data.batchNumber}}</view>
			</view>
			<view class="shipping-item flex">
				<view class="label">产品名称：</view>
				<view class="flex-1">
					{{data.productName}}
				</view>
			</view>
			<view class="shipping-item  flex">
				<view class=" flex">
					<view class="label">叶片类型：</view>
					<view class="flex-1">{{data.bladeType}}</view>
				</view>
				<view class="flex" style="margin-left: 200rpx;">
					<view class="label">驱动方式：</view>
					<view class="flex-1">{{data.driveMode}}</view>
				</view>
			</view>
		</view>

		<view class="shipping-info module-wrap bg-f radius-10 mx-20 flex"
			style="justify-content: space-between;align-items: center;" @click="gopage">
			<view class="">
				<view class="module-name fw-700">生产备注</view>
				<view class="shipping-item flex">
					<view class="flex-1">{{data.remarkProd?data.remarkProd:''}}</view>
				</view>
			</view>
			<view class="">
				<uv-icon name="arrow-right" size="16"></uv-icon>
			</view>
		</view>


		<view class="table">
			<uni-table ref="table" border stripe emptyText="暂无更多数据">
				<uni-tr v-for="(item, index) in data.productList" :key="index">
					<uni-td align="center">{{ item.serialNumber }}</uni-td>
					<uni-td align="center">{{ item.orderCustomerName }}</uni-td>
					<uni-td align="center">{{ item.sizeWidthWx }}*{{ item.sizeHeightWx }}</uni-td>
					<uni-td align="center">{{ item.bladeColor }}</uni-td>
					<uni-td>
						<view class="btnss" v-if="item.isbtnStatus == 1">
							已完成
						</view>
						<view  class="btn" @click="opens(item)">
							完成
						</view>
					</uni-td>
				</uni-tr>
			</uni-table>
		</view>

		<view class="">
			<view class="list-container">
				<view class="list-item " v-if="processFlag == 1">
					<view class="label">型材使用数量</view>
					<view class="">
						<input border="none" placeholder="请输入" placeholderStyle="#bcbcbc" fontSize="28rpx"
							v-model="data.countXc" type="digit"></input>
					</view>
				</view>
				<view class="list-item " v-if="processFlag == 4 ">
					<view class="label">电机使用数量</view>
					<view class="">
						<input border="none" placeholder="请输入" placeholderStyle="#bcbcbc" fontSize="28rpx"
							v-model="data.countDj" type="digit"></input>
					</view>
				</view>
				<view class="list-item " v-if="processFlag == 4 ">
					<view class="label">磁铁使用数量</view>
					<view>
						<input border="none" placeholder="请输入" placeholderStyle="#bcbcbc" fontSize="28rpx"
							v-model="data.countCt" type="digit"></input>
					</view>
				</view>
			</view>
		</view>

		<view class="shipping-info module-wrap bg-f radius-10 mx-20">
			<view class="">
				<view class="module-name fw-700">订单信息</view>
				<view class="shipping-item  flex">
					<view class="flex">
						<view class="label">创建时间：</view>
						<view class="flex-1">{{data.createTime}}</view>
					</view>
				</view>
			<!-- 	<view class="shipping-item  flex">
					<view class="flex">
						<view class="label">分配时间：</view>
						<view class="flex-1">{{data.groupTime}}</view>
					</view>
				</view> -->
				<view class="shipping-item  flex" v-if="data.status == '40'">
					<view class="flex">
						<view class="label">完成时间：</view>
						<view class="flex-1">{{getTime(data)}}</view>
					</view>
				</view>
			</view>
		</view>

		<view class="btns" @click="submit" v-if="processFlag == 1 || processFlag == 4">
			保存
		</view>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog :type="msgType" cancelText="取消" confirmText="确认" title="提示" :content="consts"
				@confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show2: true,
				ss: [{
					v: "10",
					n: "待分配"
				}, {
					v: "20",
					n: "待生产"
				}, {
					v: "30",
					n: "生产中"
				}, {
					v: "40",
					n: "已完成"
				}], //<!-- 待确认10 待排产20 待生产30 生产中40 待发货50 待收货61 待取货62 已收货 71已取货72 已完成90 -->
				id: "",
				data: {},
				consts: '',
				orderid: 0,
				processFlag:'',
				nobtn:false
			}
		},
		onLoad(o) {
			this.id = o.id
			this.getOrderData()
			this.processFlag = uni.getStorageSync('productionNum')
		},
		computed: {
			getSname() {
				let num = this.processFlag
				return (item) => {
					console.log(item['stepStatus'+num]);
					return item['stepStatus'+num] ==1?'已完成':'未完成'
				}
			},
			getTime(){
				let num = this.processFlag
				return (item) => {
					console.log(item['stepStatusTime'+num]);
					return item['stepStatusTime'+num] 
				}
			}
		},
		methods: {
			submit() {
				if (this.processFlag == 1) {
					if (this.data.countXc == '') {
						uni.showToast({
							icon: 'none',
							title: '请输入数量'
						})
					} else {
						this.$api.postUpdateCount({
							id: this.id,
							countXc: this.data.countXc,
							productProcessFlag:this.processFlag,
						}).then(res => {
							if (res.code == 200) {
								this.getOrderData()
								uni.showToast({
									icon: 'none',
									title: '已保存'
								})
							}
						})
					}
				} else {
						this.$api.postUpdateCount({
							id: this.id,
							countDj: this.data.countDj,
							countCt: this.data.countCt,
							productProcessFlag:this.processFlag,
						}).then(res => {
							if (res.code == 200) {
								this.getOrderData()
								uni.showToast({
									icon: 'none',
									title: '已保存'
								})
							}
						})
				}

			},
			dialogClose() {
				this.$refs.alertDialog.close()
			},
			opens(item) {
				if(this.nobtn){
					uni.showLoading({
						title:'订单未完成工序'
					})
					return
				}
				this.consts = `确认序号为${item.serialNumber}的订单是否已经完成工序？`
				this.orderid = item.id
				this.$refs.alertDialog.open()
			},
			dialogConfirm() {
				this.nobtn = true
				this.$api.postUpdateStatus({
					id: this.orderid,
					productProcessFlag:this.processFlag,
				}).then(res => {
					if (res.code == 200) {
						this.nobtn = false
						uni.hideLoading()
						this.getOrderData()
					}
				})
			},
			getOrderData() {
				this.$api.getBatchInfo({
					id: this.id
				}).then(res => {
					if (res.code == 200) {
						this.data = res.data
						let as = 'stepStatus' + this.processFlag
						this.data.productList.forEach(item => {
							item.isbtnStatus = item[as]
						})
					}
				})
			},
			gopage() {
				uni.navigateTo({
					url: `/pages/details?id=${this.id}`
				})
			}

		},
	}
</script>

<style lang="scss" scoped>
	.btns {
		width: 710rpx;
		height: 80rpx;
		background: #FF6A2F;
		border-radius: 14rpx;
		color: #FFFFFF;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 28rpx;
		color: #FFFFFF;
		line-height: 80rpx;
		text-align: center;
		margin: 40rpx auto;
	}

	.table {
		width: 710rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin: 20rpx auto;
		max-height: 500rpx;
		overflow: auto;

		.btn {
			height: 40rpx;
			background: #FF6A2F;
			border-radius: 10rpx;
			color: #FFFFFF;
			text-align: center;
			padding: 0rpx 6rpx;
			line-height: 40rpx;
		}

		.btnss {
			height: 40rpx;
			background: #FFCDB9;
			border-radius: 10rpx;
			color: #FF6A2F;
			text-align: center;
			padding: 0rpx 6rpx;
			line-height: 40rpx;
		}
	}

	.list-container {
		background-color: #FFFFFF;
		margin: 20rpx auto;
		width: 710rpx;
		border-radius: 10rpx;
		padding: 20rpx 0rpx 0rpx 20rpx;
		box-sizing: border-box;

		.list-item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1px solid #eee;
			padding: 20rpx 0rpx 30rpx 0rpx;

			input {
				text-align: right;
				padding-right: 20rpx;
			}
		}

		.list-item:last-child {
			border: none;
		}
	}

	.tts {
		width: 60rpx;
		height: 35rpx;
		background: #F51111;
		border-radius: 10rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #FFFFFF;
		line-height: 35rpx;
		text-align: center;
		margin-left: 10rpx;
	}

	.imgs {
		display: flex;
		align-items: center;
		flex-wrap: wrap;

		image {
			width: 80rpx;
			height: 80rpx;
			margin: 0 20rpx 20rpx 0;
			border: 2rpx solid #eee;
			border-radius: 6rpx;
		}
	}

	.ml20 {
		margin-left: 20rpx;
	}

	.status-and-button {
		margin: 20rpx 27rpx 0 30rpx;
	}

	.header-button {
		width: 175rpx;
		height: 60rpx;
		background: #ff4c2a;
	}

	// 配送信息
	.shipping-info {
		margin-top: 35rpx;
	}

	.shipping-item {
		font-size: 26rpx;
		color: #434343;

		.label {
			width: 134rpx;
		}
	}

	.shipping-item+.shipping-item {
		margin-top: 23rpx;
	}

	.module-wrap {
		padding: 24rpx 17rpx 30rpx;

		&+.module-wrap {
			margin-top: 18rpx;
		}

		.module-name {
			margin-bottom: 28rpx;
		}
	}

	.product-info {
		padding: 22rpx 17rpx 18rpx;
		color: #969696;
		font-size: 24rpx;

		&+.product-info {
			margin-top: 8rpx;
		}
	}

	.open-icon {
		&.open {
			transform: rotate(90deg);
		}
	}
</style>